﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class IntentAnswerInChannelsController : ControllerBase
    {

        private readonly IIntentAnswerInChannelAppService _app;
        public IntentAnswerInChannelsController(IIntentAnswerInChannelAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("answerInChannels/{id:Guid}")]
        public ActionResult<IntentAnswerInChannelDto> Get([FromRoute] Guid id, [FromQuery] string include="")
        {
            IntentAnswerInChannelDto intentAnswerInChannel = _app.Get(id, include);
            return Ok(intentAnswerInChannel);
        }

        [HttpGet]
        [Route("intents/{intentId:Guid}/answerInChannels")]
        public ActionResult<IEnumerable<IntentAnswerInChannelDto>> GetList([FromRoute] Guid intentId, [FromQuery] string include="")
        {
            IEnumerable<IntentAnswerInChannelDto> list = _app.GetList(intentId, include);
            return Ok(list);
        }

        [HttpPut]
        [Route("answerInChannels/{id:Guid}")]
        public ActionResult<IntentAnswerInChannelDto> Put([FromRoute] Guid id, [FromBody] IntentAnswerInChannelUpdateDto dto)
        {
            IntentAnswerInChannelDto intentAnswerInChannel = _app.Update(id,dto);
            return Ok(intentAnswerInChannel);
        }

        [HttpPost]
        [Route("intents/{intentId:Guid}/answerInChannels")]
        public ActionResult<IntentAnswerInChannelDto> Post([FromRoute] Guid intentId, [FromBody] IntentAnswerInChannelCreateDto dto)
        {
            IntentAnswerInChannelDto intentAnswerInChannel = _app.Add(intentId, dto);
            return CreatedAtAction(nameof(Get), new { id = intentAnswerInChannel.Id }, intentAnswerInChannel);
        }

        [HttpDelete]
        [Route("answerInChannels/{id:Guid}")]
        public ActionResult<IntentAnswerInChannelDto> Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
